<?php
/**----------------------------------------------------------------------
 * Purpose： User Class
 * 
 * CreateDate : 2014/08/19
 * Description：
 * 		Process table user
 * 
 * @package		C-UNIT Class
 * @author	 	C-UNIT SQUARE Co.,Ltd. <info@c-unit.co.jp>
 * @copyright  	Copyright(c) 2014　C-UNIT SQUARE Co.,Ltd. All Rights Reserved.
 * @license		C-UNIT SQUARE Co.,Ltd.
 ------------------------------------------------------------------------*/

class Model_User extends Zend_Db_Table_Abstract
{
	/**
	 * Name of the table
	 */
	protected $_name = 'user';
	/**
	 * Primary key of table
	 */
	protected $_primary = 'id';

	/**-------------------------------------------------------------------
	 * Select all row from table user
	 * @return array of users
	 --------------------------------------------------------------------*/
	public function selectUser()
	{
		$arrData = array();
		$objDb = Zend_Registry::get('db');
		
		// select all users
		$objSelect = $objDb->select()
						   ->from($this->_name);

		// fetch users to array
		$arrData = $objDb->fetchAll($objSelect);

		return $arrData;
	}

	/**-------------------------------------------------------------------
	 * Set value for query string
	 * @return object Zend_Db_Select
	 --------------------------------------------------------------------*/
	public function queryUser(){
        $strQuery = $this->select();
        $strQuery->from($this->_name);
        return $strQuery;
    }

    /**-------------------------------------------------------------------
	 * Paging data table User
	 * @param 	integer 	$intItemPerPage 	Number of items on one page
	 * @param 	integer 	$intPageRange		Number of page appear on screeen  
	 * @param 	integer 	$intCurrentPage		Current page
	 * @return 	object Paging data
	 --------------------------------------------------------------------*/
    public function pagingUser($intItemPerPage, $intPageRange, $intCurrentPage){
    	// get object Zend_Db_Select, set column to select
        $objDbSelect = $this->queryUser();

        // declare object Zend_Paginator_Adapter_DbSelect
        $objAdapter = new Zend_Paginator_Adapter_DbSelect($objDbSelect);

        // create object Zend_Paginator
        $objPaginator = new Zend_Paginator($objAdapter);

        // set number of items on one page
        $objPaginator->setItemCountPerPage($intItemPerPage);

        // set number of page appear on screeen        
        $objPaginator->setPageRange($intPageRange);

        // set current page to object paginator
        $objPaginator->setCurrentPageNumber($intCurrentPage);

        return $objPaginator;
    }
}